<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/11
 * Time: 13:20
 */
header('Content-Type:text/html; charset=utf-8;');
//from http://www.jb51.net/article/92435.htm

//class Computer
//{
//    public $_count = 0;
//    static $num;
//
//    public function _add()
//    {
////        return self::$num=++self::$num;
//        return self::$num++;
//        $this->_count++;  //$_count = $_count+1 $_count++
//    }
//
//    public static function add()
//    {
//        static $num = 0;
//        return ++self::$num;
//    }
//}
//
////做一个累计的效果
//$computer1 = new Computer();
//$computer1->_add();
//$computer1->_add();
//$computer1->_add();
//echo $computer1->_count;
//echo '<br />';
//echo Computer::add();
//echo Computer::add();
//echo Computer::add();
//echo '<br />';
//$computer2 = new Computer();
//$computer2->_add();
//$computer2->_add();
//$computer2->_add();
//echo $computer2->_count;
//die();

//class Computer
//{
//    public static $_count = 0;
//
//    public function _add()
//    {
//        //如果是静态成员字段，那么就应该用 self 来调用，而不是 $this
//        self::$_count++;
//    }
//}
//
////做一个累计的效果
//$computer1 = new Computer();
//$computer1->_add();
//echo Computer::$_count;
//$computer1->_add();
//echo Computer::$_count;
//$computer1->_add();
//echo Computer::$_count;
//echo '<br />';
//$computer2 = new Computer();  //第二个对象和上一个对象操作的是一个静态变量
//$computer2->_add();
//echo Computer::$_count;
//$computer2->_add();
//echo Computer::$_count;
//$computer2->_add();
//echo Computer::$_count;
class Computer {
    public static $_count = 0;
    public static function _add(){
        echo self::$_count++;
    }
}
Computer::_add();
Computer::_add();
Computer::_add();
echo Computer::$_count;
